<template>
<el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="请输入用户名">
      <el-input v-model="form.username" />
    </el-form-item>
	<el-form-item label="请输入用密码">
      <el-input v-model="form.password" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">登录</el-button>
    </el-form-item>
  </el-form>
</template>
<script setup>
import { ref } from 'vue'
import {useRoute, useRouter} from 'vue-router'
import request from '@/utils/request'
let route = useRoute()
let router = useRouter()
// do not use same name with ref
const form = ref({
  username: '',
  password: '',
})

const onSubmit = () => {
  request.post('/api/login', form.value).then(res => {
    if(res.code == '0'){
      localStorage.setItem("token",res.data)
      ElMessage({
        message: "登录成功",
        type: 'success',
      })
      router.push('/')
    }else{
      ElMessage({
        message: res.data,
        type: 'error',
      })
    }
  })
}
</script>
<style scoped lang="less">

</style>